//
//  ViewController.m
//  GStreamerTutorial2
//
//  Created by 冯思 on 15/12/1.
//  Copyright © 2015年 fengsi. All rights reserved.
//

#import "ViewController.h"
#import "GStreamerBackend.h"

@interface ViewController () {
    GStreamerBackend *gst_backend;
    AVSampleBufferDisplayLayer *sampleBufferDisplayLayer;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    play_button.enabled = FALSE;
    pause_button.enabled = FALSE;
    
    sampleBufferDisplayLayer = [[AVSampleBufferDisplayLayer alloc] init];
    sampleBufferDisplayLayer.bounds = CGRectMake(0, 0, 360, 480);
    sampleBufferDisplayLayer.backgroundColor = [UIColor blackColor].CGColor;
    sampleBufferDisplayLayer.position = CGPointMake(210, 300);
    [self.view.layer addSublayer:sampleBufferDisplayLayer];
//    [self.view displayLayer:sampleBufferDisplayLayer];
    
    gst_backend = [[GStreamerBackend alloc] init: self videoView: sampleBufferDisplayLayer];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(IBAction) play:(id)sender {
    [gst_backend play];
}

-(IBAction) pause:(id)sender {
    [gst_backend pause];
}

-(void) gstreamerInitialized {
    dispatch_async(dispatch_get_main_queue(), ^{
        play_button.enabled = TRUE;
        pause_button.enabled = TRUE;
        message_label.text = @"Ready";
    });
}

-(void) gstreamerSetUIMessage: (NSString *)message {
    dispatch_async(dispatch_get_main_queue(), ^{
        message_label.text = message;
    });
    
}

@end
